package com.appspot.menox3secandroid2011.controller;

import java.util.List;
import java.util.Map;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.RequestMap;

import com.appspot.menox3secandroid2011.model.NYUTAIRIREKI_TBL;
import com.appspot.menox3secandroid2011.model.GENBA_MST;
import com.appspot.menox3secandroid2011.model.COMPANY_MST;
import com.appspot.menox3secandroid2011.model.SAGYOSYA_MST;
import com.appspot.menox3secandroid2011.service.NyutaiRirekiItiran;
import com.appspot.menox3secandroid2011.util.Common;

public class NyutaiRirekiItiranController extends Controller {

    private NyutaiRirekiItiran service = new NyutaiRirekiItiran();

    @Override
    public Navigation run() throws Exception {

        Map<String, Object> input = new RequestMap(request);

        String genba = Common.object2string(input.get("SELECT_GENBA"));
        String company = Common.object2string(input.get("SELECT_COMPANY"));
        String sagyosya = Common.object2string(input.get("SELECT_SAGYOUSYA"));

        List<NYUTAIRIREKI_TBL> rirekiList = service.getRirekiView(genba,company,sagyosya,"",null);
        requestScope("rirekiList", rirekiList);

        List<GENBA_MST> genbaList = service.getGenbaView("");
        requestScope("genbaList", genbaList);

        List<COMPANY_MST> companyList = service.getCompanyView("");
        requestScope("companyList", companyList);

        List<SAGYOSYA_MST> sagyosyaList = service.getSagyosyaView("");
        requestScope("sagyosyaList", sagyosyaList);


        String jspName = "NyutaiRirekiItiranController.jsp";

        if(input.get("viewNo") != null){
            if(input.get("viewNo").equals("1")){
                jspName = "/Menu";
                return redirect(jspName);
            }
        }
        return forward(jspName);
    }
}
